package com.diandian.backend.client.task;

import com.diandian.backend.client.service.ClientCacheRefreshService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class ClientPermissionRefreshTask {

    private static final Logger logger = LoggerFactory.getLogger(ClientPermissionRefreshTask.class);

    @Autowired
    private ClientCacheRefreshService clientCacheRefreshService;

    /**
     * 每3分钟刷新一次redis中的权限缓存
     * 说明：仅将当前有效的客户端权限配置刷入缓存，不关注权限配置的删除
     */
    @Scheduled(cron = "0 0/10 * * * ?") // 生产使用
//    @Scheduled(cron = "0 0/1 * * * ?") // 测试使用
    public void refresh() {
        logger.info("开始执行客户端缓存刷新...");
        clientCacheRefreshService.refreshAllClientCache();
        logger.info("执行客户端缓存刷新完成。");
    }

}
